import { ElMessage } from 'element-plus'
import { ref } from 'vue'
import Public from '~/src/api/public/index.ts'

/**
 * 模块配置议程
 * 该议程定义了模块的相关配置，包括模块名称、API 路径、会议室接口定义、表格列配置、检索配置和添加配置。
 * @module meetingRoomsConfig
 */
export const moduleName = '议程'
export const moduleApi = '/api/agendaManagement'

// 模块字段
export interface Agenda {
  id?: number
  activityId: string
  fileName: string
  filePreview: string
  remark: string
}

const mockData: Agenda[] = []

/**
 * 表格列配置
 */
const tableColumns = ref<any>([
  { label: '活动ID', prop: 'activityId', minWidth: '120px' },
  { label: '议程名', prop: 'fileName', minWidth: '150px' },
  {
    label: '议程内容',
    prop: 'filePreview',
    minWidth: '150px',
    component: 'quill-viewer',
    outOfLine: true,
    componentName: '议程内容',
    componentProps: {
      title: '议程内容',
    },
    componentEvents: {
      'update:modelValue': async (content: string, row: Agenda) => {
        try {
          await Public.editApi({
            url: moduleApi,
            data: { ...row, filePreview: content },
          })
          ElMessage.success('更新成功')
          return true
        } catch {
          ElMessage.error('更新失败')
          return false
        }
      },
    },
  },
  { label: '备注', prop: 'remark', minWidth: '200px' },
])

/**
 * 获取检索配置参数
 */
const searchParams = () => [{ label: '议程名', prop: 'fileName', component: 'input', placeholder: '请输入议程名' }]

/**
 * 获取添加参数
 */
const addParams = ref<any>([
  { label: '议程名', prop: 'fileName', component: 'input', placeholder: '请输入议程名', required: true },
  { label: '议程内容', prop: 'filePreview', component: 'quill-editor', placeholder: '请输入议程内容', required: true },
  { label: '备注', prop: 'remark', component: 'textarea', placeholder: '请输入备注', required: false },
])

export { addParams, mockData, searchParams, tableColumns }
